package com.hmy.finance.manager.contract;


import cn.hutool.json.JSONUtil;
import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.contract.bo.request.contract.ContractSignTaskCancelApiRequest;
import com.hmy.contract.bo.request.contract.CreateContractRequest;
import com.hmy.contract.bo.response.contract.ContractSignTaskCancelApiResponse;
import com.hmy.contract.bo.response.contract.CreateContractResponse;
import com.hmy.contract.client.contract.ContractClient;
import com.hmy.contract.commons.enums.ContractBusinessTypeEnum;
import com.hmy.contract.commons.enums.ContractFileModelEnum;
import com.hmy.order.api.bo.request.CustomerInfoApiRequest;
import com.hmy.order.api.bo.response.OrderPrimaryApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Component
@Slf4j
public class ContractFeignClientRpc {

    @Resource
    private ContractClient contractClient;


    public CreateContractResponse createContract(CreateContractRequest createContractRequest) {
        FeignResult<CreateContractResponse> response = null;
        log.info("contractClient.createContract params:{}", JSONUtil.toJsonPrettyStr(createContractRequest));
        response = contractClient.createContract(createContractRequest);
        if (Objects.isNull(response)) {
            log.info("contractClient.createContract response is null:{}", response);
            throw new HMYRuntimeException(506300012);
        }
        if (response.isFailed()) {
            log.info("contractClient.createContract response is isFailed:{}", response);
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        log.info("contractClient.createContract response:{}", response);
        return response.getData();
    }

    public ContractSignTaskCancelApiResponse cancelContract(ContractSignTaskCancelApiRequest request) {
        FeignResult<ContractSignTaskCancelApiResponse> response;
        log.info("contractClient.cancelContract params:{}", JSONUtil.toJsonPrettyStr(request));
        response = contractClient.cancelContract(request);
        if (Objects.isNull(response)) {
            log.info("contractClient.cancelContract response is null:{}", response);
            throw new HMYRuntimeException(506300013);
        }
        if (response.isFailed()) {
            log.info("contractClient.cancelContract response is isFailed:{}", response);
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        log.info("contractClient.cancelContract response:{}", response);
        return response.getData();
    }

}
